package nagel_schreckenberg;

import java.util.ArrayList;

import nagel_schreckenberg.Lane.Direction;

public class CarDestructor implements Intersection{
	
	private Lane source;
	private Lane sink;
	private int cars;
	private int time;

	public CarDestructor(){
		sink = new Lane(100, 5);
		cars = 0;
		time = 0;
	}
	
	public void addLanes(Lane l){
		source = l;
		l.connectTarget(this);
	}
	
	@Override
	public void clearSink(){
		for(Vehicle m : sink.getVehicles()){
			cars++;
			time += m.getTravelTime();
		}
		sink.getVehicles().clear();
	}

	@Override
	public Lane getIn(Direction d) {
		return source;
	}

	@Override
	public void spawn() {}

	@Override
	public Lane getOut(Direction d) {
		return sink;
	}

	@Override
	public void controlLights() {}

	@Override
	public boolean hasSpawned() {return false;}

	@Override
	public void gershenson() {}

	@Override
	public int countSink() {
		return sink.getVehicles().size();
	}

	@Override
	public double travelTime() {
		return time/(double)cars;
	}

	@Override
	public void learning() {}

	@Override
	public void greedy() {}

}
